package com.huanzhidadi.single.thread.order;

/**
 * join方式控制线程顺序执行
 */
public class ThreadJoin {
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            System.out.println("线程t1运行");
        });
        Thread t2 = new Thread(() -> {
            try {
                // 等待t1完成
                t1.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("线程t2运行");
        });
        Thread t3 = new Thread(() -> {
            try {
                // 等待t1完成
                t2.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("线程t3运行");
        });

        t1.start();
        t2.start();
        t3.start();
        System.out.println("主线程完毕");
    }
}
